﻿<template>
  <div>
    <el-form label-width="180px" style="height: 508px; overflow: auto">
      <el-row>
        <el-col :span="24" style="margin: 5px 0">
          <el-button
            @click="previousPage"
            type="success"
            plain
            style="float: right"
            icon="el-icon-arrow-left"
          >
            返回</el-button
          >
        </el-col>
        <el-col :span="18">
          <el-form-item label="策略名称：">
            <el-input
              v-model.trim="name"
              size="mini"
              placeholder="请输入策略名称"
              disabled
              clearable
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col v-for="(item, index) in RootDevList" :span="24" :key="index">
          <el-form-item :label="item.label + '：'">
            <el-radio-group v-model="item.Status" v-if="item.Type != 2">
              <el-radio :label="3" :disabled="item.disabled">禁用</el-radio>
              <el-radio :label="4" :disabled="item.disabled">启用</el-radio>
            </el-radio-group>
            <el-radio-group v-model="item.Status" v-if="item.Type == 2">
              <el-radio :label="3">禁用</el-radio>
              <el-radio :label="4">启用</el-radio>
              <el-radio :label="1">只读</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="addTerminal" size="mini"
        >确 定</el-button
      >
      <el-button @click="resetForm" size="mini">重置</el-button>
    </span>
  </div>
</template>

<script>
export default {
  name: "mabDevice",
  data() {
    return {
      name: "",
      infoForm: [],
      RootDevList: [
        {
          Type: 2,
          label: "刻录",
          Status: "",
        },
        {
          Type: 13,
          label: "打印机",
          Status: "",
        },
        {
          Type: 16,
          label: "网卡",
          Status: "",
        },
        {
          Type: 19,
          label: "图像设备",
          Status: "",
        },
        {
          Type: 21,
          label: "智能卡读卡器",
          Status: "",
        },

        {
          Type: 28,
          label: "串口",
          Status: "",
        },
        {
          Type: 56,
          label: "多串口卡",
          Status: "",
        },
        {
          Type: 29,
          label: "并口",
          Status: "",
        },
        {
          Type: 231,
          label: "SCSI和RAID控制器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 7,
          label: "蓝牙设备",
          Status: "",
          disabled: true,
        },
        {
          Type: 6,
          label: "红外设备",
          Status: "",
          disabled: true,
        },
        {
          Type: 11,
          label: "调制解调器",
          Status: "",
          disabled: true,
        },
        {
          Type: 112,
          label: "存储驱动器",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 113,
          label: "windows CE同步设备",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 24,
          label: "软驱控制器",
          Status: "",
          disabled: true,
        },
        {
          Type: 123,
          label: "光驱",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 124,
          label: "电池及USB设备",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 125,
          label: "生物特征识别设备",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 126,
          label: "磁盘驱动器",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 127,
          label: "显示卡",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 127,
          label: "硬盘控制器",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 128,
          label: "人体学输入设备",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 129,
          label: "键盘",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 130,
          label: "显示器",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 131,
          label: "鼠标",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 132,
          label: "多媒体设备",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 133,
          label: "存储卷",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 134,
          label: "USB接口",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 4,
          label: "IEEE1394接口",
          Status: 3,
          disabled: true,
        },
        {
          Type: 141,
          label: "PCMCIA接口",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 142,
          label: "PCI/PCIE接口",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 143,
          label: "SATA/IDE接口",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 144,
          label: "PS/2接口",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 1,
          label: "普通USB存储介质",
          Status: 3,
          disabled: true,
        },
        {
          Type: 3,
          label: "软盘驱动器",
          Status: 3,
          disabled: true,
        },
        {
          Type: 8,
          label: "无线网卡",
          Status: 3,
          disabled: true,
        },
        {
          Type: 91,
          label: "SD卡",
          Status: 3,
          disabled: true,
        },
        {
          Type: 121,
          label: "通信类",
          Status: 3,
          disabled: true,
        },
        {
          Type: 15,
          label: "磁带机",
          Status: 3,
          disabled: true,
        },
        {
          Type: 18,
          label: "61883设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 20,
          label: "多功能导入装置",
          Status: 4,
          disabled: true,
        },
        {
          Type: 22,
          label: "未知USB设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 251,
          label: "卷影设备",
          Status: 3,
          disabled: true,
        },
        {
          Type: 261,
          label: "外单位优盘",
          Status: 3,
          disabled: true,
        },
        {
          Type: 27,
          label: "文件共享",
          Status: 4,
          disabled: true,
        },
        {
          Type: 30,
          label: "多功能导入装置通用口",
          Status: 4,
          disabled: true,
        },
        {
          Type: 31,
          label: "多功能导入装置涉密口",
          Status: 4,
          disabled: true,
        },
        {
          Type: 32,
          label: "虚拟机",
          Status: 3,
          disabled: true,
        },
        {
          Type: 33,
          label: "USB外置光驱",
          Status: 3,
          disabled: true,
        },
        {
          Type: 341,
          label: "打印机(网络)",
          Status: 4,
          disabled: true,
        },
        {
          Type: 100,
          label: "00(保留分类)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 300,
          label: "03(人体工学设备)",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 324,
          label: "05(物理设备)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 900,
          label: "09(集线器)",
          Status: 4,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 321,
          label: "0D(内容安全)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 322,
          label: "DC(诊断设备)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 323,
          label: "E0(无线控制器)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 324,
          label: "EF(其他设备)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
        {
          Type: 325,
          label: "FE(应用程序)",
          Status: 3,
          disabled: true,
          abtypes: true,
        },
      ],
      RootDevLists: [],
      rowData: {
        // Root:{
        //   DevList:{
        //     Dev:{}
        //   }
        // }
      },

      paramForm: {},
    };
  },
  created() {
    this.getRootDevList();
  },
  methods: {
    //返回上一页
    previousPage() {
      this.$router.go(-1);
    },
    getRootDevList() {
      this.rowData = this.$route.params;
      this.name = this.$route.params.name;
      console.log(this.$route.params, 978);
      this.infoForm = this.$route.params.Root.DevList.Dev;
      this.RootDevList.forEach((item, index) => {
        this.infoForm.forEach((it) => {
          if (item.Type == it.Type) {
            item.Status = parseInt(it.Status);
          }
        });
      });
      console.log(this.RootDevList);
    },
    //确 定
    addTerminal() {
      this.$confirm("确认要提交吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.RootDevLists = JSON.parse(JSON.stringify(this.RootDevList))
          this.RootDevLists.map((item) => {
            delete item.label;
          });
          this.RootDevLists.map((item) => {
            delete item.disabled;
          });
          let strhot = "";
          this.RootDevLists.forEach((item) => {
            if (item.Type == 13) {
              strhot = parseInt(item.Status);
            }
            if (item.Type == 34) {
              item.Status = parseInt(strhot);
            }
            if (item.Type == 56) {
              item.Status = parseInt(strhot);
            }
          });
          let arrlist = [];
          this.RootDevLists.forEach((item) => {
            if (!item.abtypes) {
              arrlist.push(item);
            }
          });

          this.paramForm.policy = {
            Root: {
              DevList: {
                Dev: arrlist,
              },
            },
            creator: "secadm",
            enableTime: this.rowData.enableTime,
            name: this.name,
            state: this.rowData.state,
          };

          console.log(this.paramForm, "sss");
          this.$postForJson("/3in1/policy/devio", this.paramForm).then(
            (jsonData) => {
              this.$message({
                type: "success",
                message: "提交成功！",
              });
              this.$router.go(-1);
            }
          );
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消提交",
          });
        });
    },
    //重置
    resetForm() {
      this.$confirm("确认要重置吗？", "提示", {
        confirmButtonText: "确 定",
        cancelButtonText: "取 消",
        type: "warning",
      })
        .then(() => {
          this.getRootDevList();
          this.$message({
            type: "success",
            message: "重置成功！",
          });
        })
        .catch((_) => {
          this.$message({
            type: "info",
            message: "已取消重置",
          });
        });
    },
  },
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 5px !important;
}
</style>
